﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using Model.RF.TestRecord;
using IDAL.RF.TestRecord;

namespace DAL.RF.TestRecord
{
    public class Action_Record : BaseRepository_DT<Action_RecordInfo>, IAction_Record
    {
        #region 静态字段部分
        private const string PARM_ID = "@ID";
        private const string PARM_SN = "@ProductSN";
        private const string PARM_RECORDTIME = "@RecordTime";
        private const string PARM_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_USERID = "@UserID";
        private const string PARM_PCIP = "@PCIP";
        private const string PARM_RESULT = "@Result";
        private const string PARM_REMARK = "@Remark";
        #endregion

        #region 检索部分
        public IList<Action_RecordInfo> LoadEntities()
        {
            return null;
        }

        public Action_RecordInfo LoadEntity<T1>(T1 id)
        {
            return null;
        }

        //----------------------------------以下为数据上传相关---------------------------------------------------------
        public bool Action_Record_Insert_ATEFlowControlCheck(Action_RecordInfo tri)
        {
            SqlParameter[] Parms = GetParameters();
            SetParameters(tri, Parms);
            SqlCommand cmd = new SqlCommand();
            foreach (SqlParameter parm in Parms)
                cmd.Parameters.Add(parm);
            try
            {
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "tb_Action_Record_Insert_ATEFlowControlCheck";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                return true;
            }
            catch
            {
                return false;
            }
        }        

        public IList<Action_RecordInfo> Action_Record_GetATEFlowControlCheck_bySN(string productSN)
        {
            SqlParameter parm = GetSNParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("Action_Record_ATEFlowControlCheck_selectByProductSN", parm);
        }
        public IList<Action_RecordInfo> Action_Record_GetATEFlowControlCheck_byDT(DateTime startTime, DateTime stopTime)
        {
            SqlParameter[] parms = GetDTParameters();
            parms[0].Value = startTime;
            parms[1].Value = stopTime;
            return ExcuteSqlToGetEntities("Action_Record_ATEFlowControlCheck_selectByDT", parms);
        }
        #endregion

        #region 参数部分
        public SqlParameter GetSNParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_SN, SqlDbType.NVarChar, 50);
            return Parm;
        }
        #endregion

        #region 重写基类部分
        public override Action_RecordInfo GetEntityRecord(SqlDataReader rdr)
        {
            Action_RecordInfo pro = new Action_RecordInfo
            {
                ID = rdr.GetInt32(0),
                ProductSN = rdr.GetValue(1).ToString(),
                RecordTime = rdr.GetDateTime(2),
                ProductTypeID = rdr.GetValue(3).ToString(),
                UserID = rdr.GetValue(4).ToString(),
                PCIP = rdr.GetValue(5).ToString(),
                Result = rdr.GetBoolean(6),
                Remark = rdr.GetValue(7).ToString(),
            };
            return pro;
        }

        //public override SqlParameter GetParameter()
        //{
        //    SqlParameter Parm = new SqlParameter(PARM_ID, SqlDbType.Int, 4);
        //    return Parm;
        //}

        public override string GetInsertsp()
        {
            return base.GetInsertsp();
        }

        public override string GetUpdatesp()
        {
            return base.GetUpdatesp();
        }

        public override string GetDeletesp()
        {
            return base.GetDeletesp();
        }
        #endregion

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_ID, SqlDbType.Int, 4),
					new SqlParameter(PARM_SN, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_RECORDTIME, SqlDbType.DateTime , 8),
                    new SqlParameter(PARM_PRODUCTTYPEID,SqlDbType.NVarChar,50),
                    new SqlParameter(PARM_USERID,SqlDbType.NVarChar,10),
                    new SqlParameter(PARM_PCIP,SqlDbType.NVarChar , 20),
                    new SqlParameter(PARM_RESULT,SqlDbType.Bit,1),
                    new SqlParameter(PARM_REMARK,SqlDbType.NVarChar,100)
                };
            return parms;
        }

        public override void SetParameters(Action_RecordInfo tci, params SqlParameter[] Parms)
        {
            Parms[0].Value = tci.ID;
            Parms[1].Value = tci.ProductSN;
            Parms[2].Value = tci.RecordTime;
            Parms[3].Value = tci.ProductTypeID;
            Parms[4].Value = tci.UserID;
            Parms[5].Value = tci.PCIP;
            Parms[6].Value = tci.Result;
            Parms[7].Value = tci.Remark;
        }
    }
}
